package com.liheng.yygh.cmn.controller;

import com.liheng.yygh.cmn.service.DictService;
import com.liheng.yygh.common.result.Result;
import com.liheng.yygh.model.cmn.Dict;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @program: yygh_partn
 * @description: 数据字典
 * @author: _LiHeng
 * @create: 2022-12-27 16:40
 **/
@Api(value = "数据字典接口")
@RestController
@RequestMapping("/admin/cmn/dict")
@CrossOrigin
public class DictController {

    @Autowired
    private DictService dictService;

    /**
     * 根据数据id查询子数据列表
     * @param id
     * @return
     */
    @ApiOperation("根据数据id查询子数据列表")
    @GetMapping("findChildData/{id}")
    public Result findChildDate(@PathVariable Long id){
        List<Dict> dictList =  dictService.findChildData(id);
        return Result.ok(dictList);
    }

    /**
     * 数据字典导出功能
     */
    @GetMapping("exportData")
    @ApiOperation("数据字典导出功能")
    public void exportData(HttpServletResponse response){
        dictService.exportDictData(response);
    }

    /**
     * 导入字典数据
     * MultipartFile 是在spring，springMVC里面提到过的使用MultipartFile得到上传文件
     */
    @PostMapping("importDictData")
    @ApiOperation("数据字典导入功能")
    public Result importDictData(MultipartFile file){
        dictService.importDictData(file);
        return Result.ok();
    }


}




